mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
chore: remove tables and add new cards
This commit is contained in:
@@ -1,156 +1,160 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
type ColumnFiltersState,
|
type ColumnDef,
|
||||||
type SortingState,
|
type ColumnFiltersState,
|
||||||
type VisibilityState,
|
type SortingState,
|
||||||
type ColumnDef,
|
type VisibilityState,
|
||||||
flexRender,
|
flexRender,
|
||||||
getCoreRowModel,
|
getCoreRowModel,
|
||||||
getFilteredRowModel,
|
getFilteredRowModel,
|
||||||
getPaginationRowModel,
|
getPaginationRowModel,
|
||||||
getSortedRowModel,
|
getSortedRowModel,
|
||||||
useReactTable,
|
useReactTable,
|
||||||
} from "@tanstack/react-table";
|
} from "@tanstack/react-table";
|
||||||
|
|
||||||
import {
|
|
||||||
Table,
|
|
||||||
TableBody,
|
|
||||||
TableCell,
|
|
||||||
TableHead,
|
|
||||||
TableHeader,
|
|
||||||
TableRow,
|
|
||||||
} from "@/components/ui/table";
|
|
||||||
import React from "react";
|
|
||||||
import {
|
|
||||||
DropdownMenu,
|
|
||||||
DropdownMenuCheckboxItem,
|
|
||||||
DropdownMenuContent,
|
|
||||||
} from "@/components/ui/dropdown-menu";
|
|
||||||
import { DropdownMenuTrigger } from "@radix-ui/react-dropdown-menu";
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { ChevronDown } from "lucide-react";
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuCheckboxItem,
|
||||||
|
DropdownMenuContent,
|
||||||
|
} from "@/components/ui/dropdown-menu";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table";
|
||||||
|
import { DropdownMenuTrigger } from "@radix-ui/react-dropdown-menu";
|
||||||
|
import { ChevronDown } from "lucide-react";
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
interface DataTableProps<TData, TValue> {
|
interface DataTableProps<TData, TValue> {
|
||||||
columns: ColumnDef<TData, TValue>[];
|
columns: ColumnDef<TData, TValue>[];
|
||||||
data: TData[];
|
data: TData[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function DataTable<TData, TValue>({
|
export function DataTable<TData, TValue>({
|
||||||
columns,
|
columns,
|
||||||
data,
|
data,
|
||||||
}: DataTableProps<TData, TValue>) {
|
}: DataTableProps<TData, TValue>) {
|
||||||
const [sorting, setSorting] = React.useState<SortingState>([]);
|
const [sorting, setSorting] = React.useState<SortingState>([]);
|
||||||
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
|
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
|
||||||
[]
|
[],
|
||||||
);
|
);
|
||||||
const [columnVisibility, setColumnVisibility] =
|
const [columnVisibility, setColumnVisibility] =
|
||||||
React.useState<VisibilityState>({});
|
React.useState<VisibilityState>({});
|
||||||
const [rowSelection, setRowSelection] = React.useState({});
|
const [rowSelection, setRowSelection] = React.useState({});
|
||||||
|
const [pagination, setPagination] = React.useState({
|
||||||
|
pageIndex: 0, //initial page index
|
||||||
|
pageSize: 8, //default page size
|
||||||
|
});
|
||||||
|
|
||||||
const table = useReactTable({
|
const table = useReactTable({
|
||||||
data,
|
data,
|
||||||
columns,
|
columns,
|
||||||
onSortingChange: setSorting,
|
onSortingChange: setSorting,
|
||||||
onColumnFiltersChange: setColumnFilters,
|
onColumnFiltersChange: setColumnFilters,
|
||||||
getCoreRowModel: getCoreRowModel(),
|
getCoreRowModel: getCoreRowModel(),
|
||||||
getPaginationRowModel: getPaginationRowModel(),
|
getPaginationRowModel: getPaginationRowModel(),
|
||||||
getSortedRowModel: getSortedRowModel(),
|
getSortedRowModel: getSortedRowModel(),
|
||||||
getFilteredRowModel: getFilteredRowModel(),
|
getFilteredRowModel: getFilteredRowModel(),
|
||||||
onColumnVisibilityChange: setColumnVisibility,
|
onColumnVisibilityChange: setColumnVisibility,
|
||||||
onRowSelectionChange: setRowSelection,
|
onRowSelectionChange: setRowSelection,
|
||||||
state: {
|
state: {
|
||||||
sorting,
|
sorting,
|
||||||
columnFilters,
|
columnFilters,
|
||||||
columnVisibility,
|
columnVisibility,
|
||||||
rowSelection,
|
rowSelection,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mt-6 grid gap-4 pb-20 w-full">
|
<div className="mt-6 grid gap-4 pb-20 w-full">
|
||||||
<div className="flex flex-col gap-4 </div>w-full overflow-auto">
|
<div className="flex flex-col gap-4 </div>w-full overflow-auto">
|
||||||
<div className="flex items-center gap-2 max-sm:flex-wrap">
|
<div className="flex items-center gap-2 max-sm:flex-wrap">
|
||||||
<Input
|
<Input
|
||||||
placeholder="Filter by name..."
|
placeholder="Filter by name..."
|
||||||
value={(table.getColumn("Name")?.getFilterValue() as string) ?? ""}
|
value={(table.getColumn("Name")?.getFilterValue() as string) ?? ""}
|
||||||
onChange={(event) =>
|
onChange={(event) =>
|
||||||
table.getColumn("Name")?.setFilterValue(event.target.value)
|
table.getColumn("Name")?.setFilterValue(event.target.value)
|
||||||
}
|
}
|
||||||
className="md:max-w-sm"
|
className="md:max-w-sm"
|
||||||
/>
|
/>
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
<Button variant="outline" className="sm:ml-auto max-sm:w-full">
|
<Button variant="outline" className="sm:ml-auto max-sm:w-full">
|
||||||
Columns <ChevronDown className="ml-2 h-4 w-4" />
|
Columns <ChevronDown className="ml-2 h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent align="end">
|
<DropdownMenuContent align="end">
|
||||||
{table
|
{table
|
||||||
.getAllColumns()
|
.getAllColumns()
|
||||||
.filter((column) => column.getCanHide())
|
.filter((column) => column.getCanHide())
|
||||||
.map((column) => {
|
.map((column) => {
|
||||||
return (
|
return (
|
||||||
<DropdownMenuCheckboxItem
|
<DropdownMenuCheckboxItem
|
||||||
key={column.id}
|
key={column.id}
|
||||||
className="capitalize"
|
className="capitalize"
|
||||||
checked={column.getIsVisible()}
|
checked={column.getIsVisible()}
|
||||||
onCheckedChange={(value) =>
|
onCheckedChange={(value) =>
|
||||||
column.toggleVisibility(!!value)
|
column.toggleVisibility(!!value)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{column.id}
|
{column.id}
|
||||||
</DropdownMenuCheckboxItem>
|
</DropdownMenuCheckboxItem>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
</div>
|
</div>
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
{table.getHeaderGroups().map((headerGroup) => (
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
<TableRow key={headerGroup.id}>
|
<TableRow key={headerGroup.id}>
|
||||||
{headerGroup.headers.map((header) => {
|
{headerGroup.headers.map((header) => {
|
||||||
return (
|
return (
|
||||||
<TableHead key={header.id}>
|
<TableHead key={header.id}>
|
||||||
{header.isPlaceholder
|
{header.isPlaceholder
|
||||||
? null
|
? null
|
||||||
: flexRender(
|
: flexRender(
|
||||||
header.column.columnDef.header,
|
header.column.columnDef.header,
|
||||||
header.getContext()
|
header.getContext(),
|
||||||
)}
|
)}
|
||||||
</TableHead>
|
</TableHead>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{table?.getRowModel()?.rows?.length ? (
|
{table?.getRowModel()?.rows?.length ? (
|
||||||
table.getRowModel().rows.map((row) => (
|
table.getRowModel().rows.map((row) => (
|
||||||
<TableRow
|
<TableRow
|
||||||
key={row.id}
|
key={row.id}
|
||||||
data-state={row.getIsSelected() && "selected"}
|
data-state={row.getIsSelected() && "selected"}
|
||||||
>
|
>
|
||||||
{row.getVisibleCells().map((cell) => (
|
{row.getVisibleCells().map((cell) => (
|
||||||
<TableCell key={cell.id}>
|
<TableCell key={cell.id}>
|
||||||
{flexRender(
|
{flexRender(
|
||||||
cell.column.columnDef.cell,
|
cell.column.columnDef.cell,
|
||||||
cell.getContext()
|
cell.getContext(),
|
||||||
)}
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
))}
|
))}
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell
|
<TableCell
|
||||||
colSpan={columns.length}
|
colSpan={columns.length}
|
||||||
className="h-24 text-center"
|
className="h-24 text-center"
|
||||||
>
|
>
|
||||||
No results.
|
No results.
|
||||||
{/* {isLoading ? (
|
{/* {isLoading ? (
|
||||||
<div className="w-full flex-col gap-2 flex items-center justify-center h-[55vh]">
|
<div className="w-full flex-col gap-2 flex items-center justify-center h-[55vh]">
|
||||||
<span className="text-muted-foreground text-lg font-medium">
|
<span className="text-muted-foreground text-lg font-medium">
|
||||||
Loading...
|
Loading...
|
||||||
@@ -159,106 +163,35 @@ export function DataTable<TData, TValue>({
|
|||||||
) : (
|
) : (
|
||||||
<>No results.</>
|
<>No results.</>
|
||||||
)} */}
|
)} */}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
)}
|
)}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
{/* <div className="rounded-md border">
|
|
||||||
{isLoading ? (
|
{data && data?.length > 0 && (
|
||||||
<div className="w-full flex-col gap-2 flex items-center justify-center h-[55vh]">
|
<div className="flex items-center justify-end space-x-2 py-4">
|
||||||
<span className="text-muted-foreground text-lg font-medium">
|
<div className="space-x-2 flex flex-wrap">
|
||||||
Loading...
|
<Button
|
||||||
</span>
|
variant="outline"
|
||||||
</div>
|
size="sm"
|
||||||
) : data?.length === 0 ? (
|
onClick={() => table.previousPage()}
|
||||||
<div className="flex-col gap-2 flex items-center justify-center h-[55vh]">
|
disabled={!table.getCanPreviousPage()}
|
||||||
<span className="text-muted-foreground text-lg font-medium">
|
>
|
||||||
No results.
|
Previous
|
||||||
</span>
|
</Button>
|
||||||
</div>
|
<Button
|
||||||
) : (
|
variant="outline"
|
||||||
<Table>
|
size="sm"
|
||||||
<TableHeader>
|
onClick={() => table.nextPage()}
|
||||||
{table.getHeaderGroups().map((headerGroup) => (
|
disabled={!table.getCanNextPage()}
|
||||||
<TableRow key={headerGroup.id}>
|
>
|
||||||
{headerGroup.headers.map((header) => {
|
Next
|
||||||
return (
|
</Button>
|
||||||
<TableHead key={header.id}>
|
</div>
|
||||||
{header.isPlaceholder
|
</div>
|
||||||
? null
|
)}
|
||||||
: flexRender(
|
</div>
|
||||||
header.column.columnDef.header,
|
</div>
|
||||||
header.getContext()
|
);
|
||||||
)}
|
|
||||||
</TableHead>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</TableRow>
|
|
||||||
))}
|
|
||||||
</TableHeader>
|
|
||||||
<TableBody>
|
|
||||||
{table?.getRowModel()?.rows?.length ? (
|
|
||||||
table.getRowModel().rows.map((row) => (
|
|
||||||
<TableRow
|
|
||||||
key={row.id}
|
|
||||||
data-state={row.getIsSelected() && "selected"}
|
|
||||||
>
|
|
||||||
{row.getVisibleCells().map((cell) => (
|
|
||||||
<TableCell key={cell.id}>
|
|
||||||
{flexRender(
|
|
||||||
cell.column.columnDef.cell,
|
|
||||||
cell.getContext()
|
|
||||||
)}
|
|
||||||
</TableCell>
|
|
||||||
))}
|
|
||||||
</TableRow>
|
|
||||||
))
|
|
||||||
) : (
|
|
||||||
<TableRow>
|
|
||||||
<TableCell
|
|
||||||
colSpan={columns.length}
|
|
||||||
className="h-24 text-center"
|
|
||||||
>
|
|
||||||
{isLoading ? (
|
|
||||||
<div className="w-full flex-col gap-2 flex items-center justify-center h-[55vh]">
|
|
||||||
<span className="text-muted-foreground text-lg font-medium">
|
|
||||||
Loading...
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<>No results.</>
|
|
||||||
)}
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
)}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
)}
|
|
||||||
</div> */}
|
|
||||||
{data && data?.length > 0 && (
|
|
||||||
<div className="flex items-center justify-end space-x-2 py-4">
|
|
||||||
<div className="space-x-2 flex flex-wrap">
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
onClick={() => table.previousPage()}
|
|
||||||
disabled={!table.getCanPreviousPage()}
|
|
||||||
>
|
|
||||||
Previous
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
onClick={() => table.nextPage()}
|
|
||||||
disabled={!table.getCanNextPage()}
|
|
||||||
>
|
|
||||||
Next
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,122 +1,117 @@
|
|||||||
import React from "react";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogDescription,
|
DialogDescription,
|
||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
DialogTrigger,
|
DialogTrigger,
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import { api } from "@/utils/api";
|
|
||||||
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
||||||
import { DataTable } from "./data-table";
|
import { api } from "@/utils/api";
|
||||||
|
import { Layers, LoaderIcon } from "lucide-react";
|
||||||
|
import React from "react";
|
||||||
import { columns } from "./columns";
|
import { columns } from "./columns";
|
||||||
import { LoaderIcon } from "lucide-react";
|
import { DataTable } from "./data-table";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
nodeName: string;
|
nodeName: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ApplicationList {
|
interface ApplicationList {
|
||||||
ID: string;
|
ID: string;
|
||||||
Image: string;
|
Image: string;
|
||||||
Mode: string;
|
Mode: string;
|
||||||
Name: string;
|
Name: string;
|
||||||
Ports: string;
|
Ports: string;
|
||||||
Replicas: string;
|
Replicas: string;
|
||||||
CurrentState: string;
|
CurrentState: string;
|
||||||
DesiredState: string;
|
DesiredState: string;
|
||||||
Error: string;
|
Error: string;
|
||||||
Node: string;
|
Node: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ShowNodeApplications = ({ nodeName }: Props) => {
|
const ShowNodeApplications = ({ nodeName }: Props) => {
|
||||||
const [loading, setLoading] = React.useState(true);
|
const [loading, setLoading] = React.useState(true);
|
||||||
const { data: NodeApps, isLoading: NodeAppsLoading } =
|
const { data: NodeApps, isLoading: NodeAppsLoading } =
|
||||||
api.swarm.getNodeApps.useQuery();
|
api.swarm.getNodeApps.useQuery();
|
||||||
|
|
||||||
let applicationList = "";
|
let applicationList = "";
|
||||||
|
|
||||||
if (NodeApps && NodeApps.length > 0) {
|
if (NodeApps && NodeApps.length > 0) {
|
||||||
applicationList = NodeApps.map((app) => app.Name).join(" ");
|
applicationList = NodeApps.map((app) => app.Name).join(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data: NodeAppDetails, isLoading: NodeAppDetailsLoading } =
|
const { data: NodeAppDetails, isLoading: NodeAppDetailsLoading } =
|
||||||
api.swarm.getAppInfos.useQuery({ appName: applicationList });
|
api.swarm.getAppInfos.useQuery({ appName: applicationList });
|
||||||
|
|
||||||
if (NodeAppsLoading || NodeAppDetailsLoading) {
|
if (NodeAppsLoading || NodeAppDetailsLoading) {
|
||||||
return (
|
return (
|
||||||
<Dialog>
|
<Dialog>
|
||||||
<DialogTrigger asChild>
|
<DialogTrigger asChild>
|
||||||
<DropdownMenuItem
|
<Button variant="outline" size="sm" className="w-full">
|
||||||
className="w-full cursor-pointer"
|
<LoaderIcon className="h-4 w-4 mr-2 animate-spin" />
|
||||||
disabled
|
</Button>
|
||||||
onSelect={(e) => e.preventDefault()}
|
</DialogTrigger>
|
||||||
>
|
</Dialog>
|
||||||
<LoaderIcon className="animate-spin h-5 w-5" />
|
);
|
||||||
</DropdownMenuItem>
|
}
|
||||||
</DialogTrigger>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!NodeApps || !NodeAppDetails) {
|
if (!NodeApps || !NodeAppDetails) {
|
||||||
return <div>No data found</div>;
|
return <div>No data found</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const combinedData: ApplicationList[] = NodeApps.flatMap((app) => {
|
const combinedData: ApplicationList[] = NodeApps.flatMap((app) => {
|
||||||
const appDetails =
|
const appDetails =
|
||||||
NodeAppDetails?.filter((detail) =>
|
NodeAppDetails?.filter((detail) =>
|
||||||
detail.Name.startsWith(`${app.Name}.`)
|
detail.Name.startsWith(`${app.Name}.`),
|
||||||
) || [];
|
) || [];
|
||||||
|
|
||||||
if (appDetails.length === 0) {
|
if (appDetails.length === 0) {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
...app,
|
...app,
|
||||||
CurrentState: "N/A",
|
CurrentState: "N/A",
|
||||||
DesiredState: "N/A",
|
DesiredState: "N/A",
|
||||||
Error: "",
|
Error: "",
|
||||||
Node: "N/A",
|
Node: "N/A",
|
||||||
Ports: app.Ports,
|
Ports: app.Ports,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return appDetails.map((detail) => ({
|
return appDetails.map((detail) => ({
|
||||||
...app,
|
...app,
|
||||||
CurrentState: detail.CurrentState,
|
CurrentState: detail.CurrentState,
|
||||||
DesiredState: detail.DesiredState,
|
DesiredState: detail.DesiredState,
|
||||||
Error: detail.Error,
|
Error: detail.Error,
|
||||||
Node: detail.Node,
|
Node: detail.Node,
|
||||||
Ports: detail.Ports || app.Ports,
|
Ports: detail.Ports || app.Ports,
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog>
|
<Dialog>
|
||||||
<DialogTrigger asChild>
|
<DialogTrigger asChild>
|
||||||
<DropdownMenuItem
|
<Button variant="outline" size="sm" className="w-full">
|
||||||
className="w-full cursor-pointer"
|
<Layers className="h-4 w-4 mr-2" />
|
||||||
onSelect={(e) => e.preventDefault()}
|
Services
|
||||||
>
|
</Button>
|
||||||
Show Applications
|
</DialogTrigger>
|
||||||
</DropdownMenuItem>
|
<DialogContent className={"sm:max-w-5xl overflow-y-auto max-h-screen"}>
|
||||||
</DialogTrigger>
|
<DialogHeader>
|
||||||
<DialogContent className={"sm:max-w-5xl overflow-y-auto max-h-screen"}>
|
<DialogTitle>Node Applications</DialogTitle>
|
||||||
<DialogHeader>
|
<DialogDescription>
|
||||||
<DialogTitle>Node Applications</DialogTitle>
|
See in detail the applications running on this node
|
||||||
<DialogDescription>
|
</DialogDescription>
|
||||||
See in detail the applications running on this node
|
</DialogHeader>
|
||||||
</DialogDescription>
|
<div className="max-h-[90vh]">
|
||||||
</DialogHeader>
|
<DataTable columns={columns} data={combinedData ?? []} />
|
||||||
<div className="max-h-[90vh]">
|
</div>
|
||||||
<DataTable columns={columns} data={combinedData ?? []} />
|
{/* <div className="text-wrap rounded-lg border p-4 text-sm sm:max-w-[59rem] bg-card max-h-[70vh] overflow-auto"></div> */}
|
||||||
</div>
|
</DialogContent>
|
||||||
{/* <div className="text-wrap rounded-lg border p-4 text-sm sm:max-w-[59rem] bg-card max-h-[70vh] overflow-auto"></div> */}
|
</Dialog>
|
||||||
</DialogContent>
|
);
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ShowNodeApplications;
|
export default ShowNodeApplications;
|
||||||
|
|||||||
139
apps/dokploy/components/dashboard/swarm/containers/columns.tsx
Normal file
139
apps/dokploy/components/dashboard/swarm/containers/columns.tsx
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
import type { ColumnDef } from "@tanstack/react-table";
|
||||||
|
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 type { Badge } from "@/components/ui/badge";
|
||||||
|
import { ShowNodeConfig } from "../details/show-node";
|
||||||
|
// import { ShowContainerConfig } from "../config/show-container-config";
|
||||||
|
// import { ShowDockerModalLogs } from "../logs/show-docker-modal-logs";
|
||||||
|
// import { DockerTerminalModal } from "../terminal/docker-terminal-modal";
|
||||||
|
// import type { Container } from "./show-containers";
|
||||||
|
|
||||||
|
export interface ContainerList {
|
||||||
|
containerId: string;
|
||||||
|
name: string;
|
||||||
|
image: string;
|
||||||
|
ports: string;
|
||||||
|
state: string;
|
||||||
|
status: string;
|
||||||
|
serverId: string | null | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const columns: ColumnDef<ContainerList>[] = [
|
||||||
|
{
|
||||||
|
accessorKey: "ID",
|
||||||
|
accessorFn: (row) => row.containerId,
|
||||||
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
>
|
||||||
|
ID
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return <div>{row.getValue("containerId")}</div>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "Name",
|
||||||
|
accessorFn: (row) => row.name,
|
||||||
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
>
|
||||||
|
Name
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return <div>{row.getValue("name")}</div>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "Image",
|
||||||
|
accessorFn: (row) => row.image,
|
||||||
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
>
|
||||||
|
Image
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return <div>{row.getValue("image")}</div>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "Ports",
|
||||||
|
accessorFn: (row) => row.ports,
|
||||||
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
>
|
||||||
|
Ports
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return <div>{row.getValue("ports")}</div>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "State",
|
||||||
|
accessorFn: (row) => row.state,
|
||||||
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
>
|
||||||
|
State
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return <div>{row.getValue("state")}</div>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "Status",
|
||||||
|
accessorFn: (row) => row.status,
|
||||||
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
>
|
||||||
|
Status
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return <div>{row.getValue("status")}</div>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
@@ -0,0 +1,210 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import {
|
||||||
|
type ColumnDef,
|
||||||
|
type ColumnFiltersState,
|
||||||
|
type SortingState,
|
||||||
|
type VisibilityState,
|
||||||
|
flexRender,
|
||||||
|
getCoreRowModel,
|
||||||
|
getFilteredRowModel,
|
||||||
|
getPaginationRowModel,
|
||||||
|
getSortedRowModel,
|
||||||
|
useReactTable,
|
||||||
|
} from "@tanstack/react-table";
|
||||||
|
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuCheckboxItem,
|
||||||
|
DropdownMenuContent,
|
||||||
|
} from "@/components/ui/dropdown-menu";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table";
|
||||||
|
import { DropdownMenuTrigger } from "@radix-ui/react-dropdown-menu";
|
||||||
|
import { ChevronDown } from "lucide-react";
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
|
interface DataTableProps<TData, TValue> {
|
||||||
|
columns: ColumnDef<TData, TValue>[];
|
||||||
|
data: TData[];
|
||||||
|
isLoading: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DataTable<TData, TValue>({
|
||||||
|
columns,
|
||||||
|
data,
|
||||||
|
isLoading,
|
||||||
|
}: DataTableProps<TData, TValue>) {
|
||||||
|
const [sorting, setSorting] = React.useState<SortingState>([]);
|
||||||
|
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
const [columnVisibility, setColumnVisibility] =
|
||||||
|
React.useState<VisibilityState>({});
|
||||||
|
const [rowSelection, setRowSelection] = React.useState({});
|
||||||
|
|
||||||
|
const table = useReactTable({
|
||||||
|
data,
|
||||||
|
columns,
|
||||||
|
onSortingChange: setSorting,
|
||||||
|
onColumnFiltersChange: setColumnFilters,
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
getPaginationRowModel: getPaginationRowModel(),
|
||||||
|
getSortedRowModel: getSortedRowModel(),
|
||||||
|
getFilteredRowModel: getFilteredRowModel(),
|
||||||
|
onColumnVisibilityChange: setColumnVisibility,
|
||||||
|
onRowSelectionChange: setRowSelection,
|
||||||
|
state: {
|
||||||
|
sorting,
|
||||||
|
columnFilters,
|
||||||
|
columnVisibility,
|
||||||
|
rowSelection,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="mt-6 grid gap-4 pb-20 w-full">
|
||||||
|
<div className="flex flex-col gap-4 </div>w-full overflow-auto">
|
||||||
|
<div className="flex items-center gap-2 max-sm:flex-wrap">
|
||||||
|
<Input
|
||||||
|
placeholder="Filter by name..."
|
||||||
|
value={(table.getColumn("Name")?.getFilterValue() as string) ?? ""}
|
||||||
|
onChange={(event) =>
|
||||||
|
table.getColumn("Name")?.setFilterValue(event.target.value)
|
||||||
|
}
|
||||||
|
className="md:max-w-sm"
|
||||||
|
/>
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant="outline" className="sm:ml-auto max-sm:w-full">
|
||||||
|
Columns <ChevronDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end">
|
||||||
|
{table
|
||||||
|
.getAllColumns()
|
||||||
|
.filter((column) => column.getCanHide())
|
||||||
|
.map((column) => {
|
||||||
|
return (
|
||||||
|
<DropdownMenuCheckboxItem
|
||||||
|
key={column.id}
|
||||||
|
className="capitalize"
|
||||||
|
checked={column.getIsVisible()}
|
||||||
|
onCheckedChange={(value) =>
|
||||||
|
column.toggleVisibility(!!value)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{column.id}
|
||||||
|
</DropdownMenuCheckboxItem>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="rounded-md border">
|
||||||
|
{isLoading ? (
|
||||||
|
<div className="w-full flex-col gap-2 flex items-center justify-center h-[55vh]">
|
||||||
|
<span className="text-muted-foreground text-lg font-medium">
|
||||||
|
Loading...
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
) : data?.length === 0 ? (
|
||||||
|
<div className="flex-col gap-2 flex items-center justify-center h-[55vh]">
|
||||||
|
<span className="text-muted-foreground text-lg font-medium">
|
||||||
|
No results.
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
|
<TableRow key={headerGroup.id}>
|
||||||
|
{headerGroup.headers.map((header) => {
|
||||||
|
return (
|
||||||
|
<TableHead key={header.id}>
|
||||||
|
{header.isPlaceholder
|
||||||
|
? null
|
||||||
|
: flexRender(
|
||||||
|
header.column.columnDef.header,
|
||||||
|
header.getContext(),
|
||||||
|
)}
|
||||||
|
</TableHead>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{table?.getRowModel()?.rows?.length ? (
|
||||||
|
table.getRowModel().rows.map((row) => (
|
||||||
|
<TableRow
|
||||||
|
key={row.id}
|
||||||
|
data-state={row.getIsSelected() && "selected"}
|
||||||
|
>
|
||||||
|
{row.getVisibleCells().map((cell) => (
|
||||||
|
<TableCell key={cell.id}>
|
||||||
|
{flexRender(
|
||||||
|
cell.column.columnDef.cell,
|
||||||
|
cell.getContext(),
|
||||||
|
)}
|
||||||
|
</TableCell>
|
||||||
|
))}
|
||||||
|
</TableRow>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell
|
||||||
|
colSpan={columns.length}
|
||||||
|
className="h-24 text-center"
|
||||||
|
>
|
||||||
|
{isLoading ? (
|
||||||
|
<div className="w-full flex-col gap-2 flex items-center justify-center h-[55vh]">
|
||||||
|
<span className="text-muted-foreground text-lg font-medium">
|
||||||
|
Loading...
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<>No results.</>
|
||||||
|
)}
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{data && data?.length > 0 && (
|
||||||
|
<div className="flex items-center justify-end space-x-2 py-4">
|
||||||
|
<div className="space-x-2 flex flex-wrap">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => table.previousPage()}
|
||||||
|
disabled={!table.getCanPreviousPage()}
|
||||||
|
>
|
||||||
|
Previous
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => table.nextPage()}
|
||||||
|
disabled={!table.getCanNextPage()}
|
||||||
|
>
|
||||||
|
Next
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogTrigger,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
|
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
||||||
|
import { api } from "@/utils/api";
|
||||||
|
import React from "react";
|
||||||
|
import { ShowContainers } from "../../docker/show/show-containers";
|
||||||
|
import { columns } from "./columns";
|
||||||
|
import { DataTable } from "./data-table";
|
||||||
|
// import { columns } from "./columns";
|
||||||
|
// import { DataTable } from "./data-table";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
serverId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ShowNodeContainers = ({ serverId }: Props) => {
|
||||||
|
return (
|
||||||
|
<Dialog>
|
||||||
|
<DialogTrigger asChild>
|
||||||
|
<DropdownMenuItem
|
||||||
|
className="w-full cursor-pointer"
|
||||||
|
onSelect={(e) => e.preventDefault()}
|
||||||
|
>
|
||||||
|
Show Container
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</DialogTrigger>
|
||||||
|
<DialogContent className={"sm:max-w-5xl overflow-y-auto max-h-screen"}>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Node Container</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
See all containers running on this node
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className="text-wrap rounded-lg border p-4 text-sm sm:max-w-[59rem] bg-card max-h-[90vh] overflow-auto ">
|
||||||
|
<ShowContainers serverId={serverId} />
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ShowNodeContainers;
|
||||||
@@ -1,54 +1,60 @@
|
|||||||
import React from "react";
|
import { CodeEditor } from "@/components/shared/code-editor";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogDescription,
|
DialogDescription,
|
||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
DialogTrigger,
|
DialogTrigger,
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
||||||
import { CodeEditor } from "@/components/shared/code-editor";
|
|
||||||
import { api } from "@/utils/api";
|
import { api } from "@/utils/api";
|
||||||
|
import { Settings } from "lucide-react";
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
nodeId: string;
|
nodeId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ShowNodeConfig = ({ nodeId }: Props) => {
|
export const ShowNodeConfig = ({ nodeId }: Props) => {
|
||||||
const { data, isLoading } = api.swarm.getNodeInfo.useQuery({ nodeId });
|
const { data, isLoading } = api.swarm.getNodeInfo.useQuery({ nodeId });
|
||||||
return (
|
return (
|
||||||
<Dialog>
|
<Dialog>
|
||||||
<DialogTrigger asChild>
|
<DialogTrigger asChild>
|
||||||
<DropdownMenuItem
|
{/* <DropdownMenuItem
|
||||||
className="w-full cursor-pointer"
|
className="w-full cursor-pointer"
|
||||||
onSelect={(e) => e.preventDefault()}
|
onSelect={(e) => e.preventDefault()}
|
||||||
>
|
>
|
||||||
View Config
|
Show Config
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem> */}
|
||||||
</DialogTrigger>
|
<Button variant="outline" size="sm" className="w-full">
|
||||||
<DialogContent className={"sm:max-w-5xl overflow-y-auto max-h-screen"}>
|
<Settings className="h-4 w-4 mr-2" />
|
||||||
<DialogHeader>
|
Config
|
||||||
<DialogTitle>Node Config</DialogTitle>
|
</Button>
|
||||||
<DialogDescription>
|
</DialogTrigger>
|
||||||
See in detail the metadata of this node
|
<DialogContent className={"sm:max-w-5xl overflow-y-auto max-h-screen"}>
|
||||||
</DialogDescription>
|
<DialogHeader>
|
||||||
</DialogHeader>
|
<DialogTitle>Node Config</DialogTitle>
|
||||||
<div className="text-wrap rounded-lg border p-4 text-sm sm:max-w-[59rem] bg-card max-h-[70vh] overflow-auto ">
|
<DialogDescription>
|
||||||
<code>
|
See in detail the metadata of this node
|
||||||
<pre className="whitespace-pre-wrap break-words items-center justify-center">
|
</DialogDescription>
|
||||||
{/* {JSON.stringify(data, null, 2)} */}
|
</DialogHeader>
|
||||||
<CodeEditor
|
<div className="text-wrap rounded-lg border p-4 text-sm sm:max-w-[59rem] bg-card max-h-[70vh] overflow-auto ">
|
||||||
language="json"
|
<code>
|
||||||
lineWrapping={false}
|
<pre className="whitespace-pre-wrap break-words items-center justify-center">
|
||||||
lineNumbers={false}
|
{/* {JSON.stringify(data, null, 2)} */}
|
||||||
readOnly
|
<CodeEditor
|
||||||
value={JSON.stringify(data, null, 2)}
|
language="json"
|
||||||
/>
|
lineWrapping={false}
|
||||||
</pre>
|
lineNumbers={false}
|
||||||
</code>
|
readOnly
|
||||||
</div>
|
value={JSON.stringify(data, null, 2)}
|
||||||
</DialogContent>
|
/>
|
||||||
</Dialog>
|
</pre>
|
||||||
);
|
</code>
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
168
apps/dokploy/components/dashboard/swarm/servers/columns.tsx
Normal file
168
apps/dokploy/components/dashboard/swarm/servers/columns.tsx
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
import type { ColumnDef } from "@tanstack/react-table";
|
||||||
|
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 type { Badge } from "@/components/ui/badge";
|
||||||
|
import { ShowContainers } from "../../docker/show/show-containers";
|
||||||
|
import ShowNodeContainers from "../containers/show-container";
|
||||||
|
import { ShowNodeConfig } from "../details/show-node";
|
||||||
|
// import { ShowContainerConfig } from "../config/show-container-config";
|
||||||
|
// import { ShowDockerModalLogs } from "../logs/show-docker-modal-logs";
|
||||||
|
// import { DockerTerminalModal } from "../terminal/docker-terminal-modal";
|
||||||
|
// import type { Container } from "./show-containers";
|
||||||
|
|
||||||
|
export interface ServerList {
|
||||||
|
totalSum: number;
|
||||||
|
serverId: string;
|
||||||
|
name: string;
|
||||||
|
description: string | null;
|
||||||
|
ipAddress: string;
|
||||||
|
port: number;
|
||||||
|
username: string;
|
||||||
|
appName: string;
|
||||||
|
enableDockerCleanup: boolean;
|
||||||
|
createdAt: string;
|
||||||
|
adminId: string;
|
||||||
|
serverStatus: "active" | "inactive";
|
||||||
|
command: string;
|
||||||
|
sshKeyId: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const columns: ColumnDef<ServerList>[] = [
|
||||||
|
{
|
||||||
|
accessorKey: "serverId",
|
||||||
|
accessorFn: (row) => row.serverId,
|
||||||
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
>
|
||||||
|
Server ID
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return <div>{row.getValue("serverId")}</div>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "name",
|
||||||
|
accessorFn: (row) => row.name,
|
||||||
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
>
|
||||||
|
Name
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return <div>{row.getValue("name")}</div>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "ipAddress",
|
||||||
|
accessorFn: (row) => row.ipAddress,
|
||||||
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
>
|
||||||
|
IP Address
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return <div>{row.getValue("ipAddress")}</div>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "port",
|
||||||
|
accessorFn: (row) => row.port,
|
||||||
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
>
|
||||||
|
Port
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return <div>{row.getValue("port")}</div>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "username",
|
||||||
|
accessorFn: (row) => row.username,
|
||||||
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
>
|
||||||
|
Username
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return <div>{row.getValue("username")}</div>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "createdAt",
|
||||||
|
accessorFn: (row) => row.createdAt,
|
||||||
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
>
|
||||||
|
Created at
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return <div>{row.getValue("createdAt")}</div>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "actions",
|
||||||
|
enableHiding: false,
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<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>
|
||||||
|
<ShowNodeContainers serverId={row.original.serverId} />
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
210
apps/dokploy/components/dashboard/swarm/servers/data-table.tsx
Normal file
210
apps/dokploy/components/dashboard/swarm/servers/data-table.tsx
Normal file
@@ -0,0 +1,210 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import {
|
||||||
|
type ColumnDef,
|
||||||
|
type ColumnFiltersState,
|
||||||
|
type SortingState,
|
||||||
|
type VisibilityState,
|
||||||
|
flexRender,
|
||||||
|
getCoreRowModel,
|
||||||
|
getFilteredRowModel,
|
||||||
|
getPaginationRowModel,
|
||||||
|
getSortedRowModel,
|
||||||
|
useReactTable,
|
||||||
|
} from "@tanstack/react-table";
|
||||||
|
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuCheckboxItem,
|
||||||
|
DropdownMenuContent,
|
||||||
|
} from "@/components/ui/dropdown-menu";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table";
|
||||||
|
import { DropdownMenuTrigger } from "@radix-ui/react-dropdown-menu";
|
||||||
|
import { ChevronDown } from "lucide-react";
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
|
interface DataTableProps<TData, TValue> {
|
||||||
|
columns: ColumnDef<TData, TValue>[];
|
||||||
|
data: TData[];
|
||||||
|
isLoading: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DataTable<TData, TValue>({
|
||||||
|
columns,
|
||||||
|
data,
|
||||||
|
isLoading,
|
||||||
|
}: DataTableProps<TData, TValue>) {
|
||||||
|
const [sorting, setSorting] = React.useState<SortingState>([]);
|
||||||
|
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
const [columnVisibility, setColumnVisibility] =
|
||||||
|
React.useState<VisibilityState>({});
|
||||||
|
const [rowSelection, setRowSelection] = React.useState({});
|
||||||
|
|
||||||
|
const table = useReactTable({
|
||||||
|
data,
|
||||||
|
columns,
|
||||||
|
onSortingChange: setSorting,
|
||||||
|
onColumnFiltersChange: setColumnFilters,
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
getPaginationRowModel: getPaginationRowModel(),
|
||||||
|
getSortedRowModel: getSortedRowModel(),
|
||||||
|
getFilteredRowModel: getFilteredRowModel(),
|
||||||
|
onColumnVisibilityChange: setColumnVisibility,
|
||||||
|
onRowSelectionChange: setRowSelection,
|
||||||
|
state: {
|
||||||
|
sorting,
|
||||||
|
columnFilters,
|
||||||
|
columnVisibility,
|
||||||
|
rowSelection,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="mt-6 grid gap-4 pb-20 w-full">
|
||||||
|
<div className="flex flex-col gap-4 </div>w-full overflow-auto">
|
||||||
|
<div className="flex items-center gap-2 max-sm:flex-wrap">
|
||||||
|
<Input
|
||||||
|
placeholder="Filter by name..."
|
||||||
|
value={(table.getColumn("Name")?.getFilterValue() as string) ?? ""}
|
||||||
|
onChange={(event) =>
|
||||||
|
table.getColumn("Name")?.setFilterValue(event.target.value)
|
||||||
|
}
|
||||||
|
className="md:max-w-sm"
|
||||||
|
/>
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant="outline" className="sm:ml-auto max-sm:w-full">
|
||||||
|
Columns <ChevronDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end">
|
||||||
|
{table
|
||||||
|
.getAllColumns()
|
||||||
|
.filter((column) => column.getCanHide())
|
||||||
|
.map((column) => {
|
||||||
|
return (
|
||||||
|
<DropdownMenuCheckboxItem
|
||||||
|
key={column.id}
|
||||||
|
className="capitalize"
|
||||||
|
checked={column.getIsVisible()}
|
||||||
|
onCheckedChange={(value) =>
|
||||||
|
column.toggleVisibility(!!value)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{column.id}
|
||||||
|
</DropdownMenuCheckboxItem>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="rounded-md border">
|
||||||
|
{isLoading ? (
|
||||||
|
<div className="w-full flex-col gap-2 flex items-center justify-center h-[55vh]">
|
||||||
|
<span className="text-muted-foreground text-lg font-medium">
|
||||||
|
Loading...
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
) : data?.length === 0 ? (
|
||||||
|
<div className="flex-col gap-2 flex items-center justify-center h-[55vh]">
|
||||||
|
<span className="text-muted-foreground text-lg font-medium">
|
||||||
|
No results.
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
|
<TableRow key={headerGroup.id}>
|
||||||
|
{headerGroup.headers.map((header) => {
|
||||||
|
return (
|
||||||
|
<TableHead key={header.id}>
|
||||||
|
{header.isPlaceholder
|
||||||
|
? null
|
||||||
|
: flexRender(
|
||||||
|
header.column.columnDef.header,
|
||||||
|
header.getContext(),
|
||||||
|
)}
|
||||||
|
</TableHead>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{table?.getRowModel()?.rows?.length ? (
|
||||||
|
table.getRowModel().rows.map((row) => (
|
||||||
|
<TableRow
|
||||||
|
key={row.id}
|
||||||
|
data-state={row.getIsSelected() && "selected"}
|
||||||
|
>
|
||||||
|
{row.getVisibleCells().map((cell) => (
|
||||||
|
<TableCell key={cell.id}>
|
||||||
|
{flexRender(
|
||||||
|
cell.column.columnDef.cell,
|
||||||
|
cell.getContext(),
|
||||||
|
)}
|
||||||
|
</TableCell>
|
||||||
|
))}
|
||||||
|
</TableRow>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell
|
||||||
|
colSpan={columns.length}
|
||||||
|
className="h-24 text-center"
|
||||||
|
>
|
||||||
|
{isLoading ? (
|
||||||
|
<div className="w-full flex-col gap-2 flex items-center justify-center h-[55vh]">
|
||||||
|
<span className="text-muted-foreground text-lg font-medium">
|
||||||
|
Loading...
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<>No results.</>
|
||||||
|
)}
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{data && data?.length > 0 && (
|
||||||
|
<div className="flex items-center justify-end space-x-2 py-4">
|
||||||
|
<div className="space-x-2 flex flex-wrap">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => table.previousPage()}
|
||||||
|
disabled={!table.getCanPreviousPage()}
|
||||||
|
>
|
||||||
|
Previous
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => table.nextPage()}
|
||||||
|
disabled={!table.getCanNextPage()}
|
||||||
|
>
|
||||||
|
Next
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { api } from "@/utils/api";
|
||||||
|
import React from "react";
|
||||||
|
import { columns } from "./columns";
|
||||||
|
import { DataTable } from "./data-table";
|
||||||
|
|
||||||
|
function ShowApplicationServers() {
|
||||||
|
const { data, isLoading } = api.server.all.useQuery();
|
||||||
|
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DataTable columns={columns} data={data ?? []} isLoading={isLoading} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ShowApplicationServers;
|
||||||
@@ -4,180 +4,181 @@ import * as React from "react";
|
|||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
DropdownMenuLabel,
|
DropdownMenuLabel,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
|
|
||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
import { ShowNodeConfig } from "../details/show-node";
|
|
||||||
import ShowNodeApplications from "../applications/show-applications";
|
import ShowNodeApplications from "../applications/show-applications";
|
||||||
|
import ShowContainers from "../containers/show-container";
|
||||||
|
import { ShowNodeConfig } from "../details/show-node";
|
||||||
// import { ShowContainerConfig } from "../config/show-container-config";
|
// import { ShowContainerConfig } from "../config/show-container-config";
|
||||||
// import { ShowDockerModalLogs } from "../logs/show-docker-modal-logs";
|
// import { ShowDockerModalLogs } from "../logs/show-docker-modal-logs";
|
||||||
// import { DockerTerminalModal } from "../terminal/docker-terminal-modal";
|
// import { DockerTerminalModal } from "../terminal/docker-terminal-modal";
|
||||||
// import type { Container } from "./show-containers";
|
// import type { Container } from "./show-containers";
|
||||||
|
|
||||||
export interface SwarmList {
|
export interface SwarmList {
|
||||||
ID: string;
|
ID: string;
|
||||||
Hostname: string;
|
Hostname: string;
|
||||||
Availability: string;
|
Availability: string;
|
||||||
EngineVersion: string;
|
EngineVersion: string;
|
||||||
Status: string;
|
Status: string;
|
||||||
ManagerStatus: string;
|
ManagerStatus: string;
|
||||||
TLSStatus: string;
|
TLSStatus: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const columns: ColumnDef<SwarmList>[] = [
|
export const columns: ColumnDef<SwarmList>[] = [
|
||||||
{
|
{
|
||||||
accessorKey: "ID",
|
accessorKey: "ID",
|
||||||
header: ({ column }) => {
|
header: ({ column }) => {
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
>
|
>
|
||||||
ID
|
ID
|
||||||
<ArrowUpDown className="ml-2 h-4 w-4" />
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
return <div>{row.getValue("ID")}</div>;
|
return <div>{row.getValue("ID")}</div>;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "EngineVersion",
|
accessorKey: "EngineVersion",
|
||||||
header: ({ column }) => {
|
header: ({ column }) => {
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
>
|
>
|
||||||
Engine Version
|
Engine Version
|
||||||
<ArrowUpDown className="ml-2 h-4 w-4" />
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
return <div>{row.getValue("EngineVersion")}</div>;
|
return <div>{row.getValue("EngineVersion")}</div>;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "Hostname",
|
accessorKey: "Hostname",
|
||||||
header: ({ column }) => {
|
header: ({ column }) => {
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
>
|
>
|
||||||
Hostname
|
Hostname
|
||||||
<ArrowUpDown className="ml-2 h-4 w-4" />
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
return <div>{row.getValue("Hostname")}</div>;
|
return <div>{row.getValue("Hostname")}</div>;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// {
|
// {
|
||||||
// accessorKey: "Status",
|
// accessorKey: "Status",
|
||||||
// header: ({ column }) => {
|
// header: ({ column }) => {
|
||||||
// return (
|
// return (
|
||||||
// <Button
|
// <Button
|
||||||
// variant="ghost"
|
// variant="ghost"
|
||||||
// onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
// onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
// >
|
// >
|
||||||
// Status
|
// Status
|
||||||
// <ArrowUpDown className="ml-2 h-4 w-4" />
|
// <ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
// </Button>
|
// </Button>
|
||||||
// );
|
// );
|
||||||
// },
|
// },
|
||||||
// cell: ({ row }) => {
|
// cell: ({ row }) => {
|
||||||
// const value = row.getValue("status") as string;
|
// const value = row.getValue("status") as string;
|
||||||
// return (
|
// return (
|
||||||
// <div className="capitalize">
|
// <div className="capitalize">
|
||||||
// <Badge
|
// <Badge
|
||||||
// variant={
|
// variant={
|
||||||
// value === "Ready"
|
// value === "Ready"
|
||||||
// ? "default"
|
// ? "default"
|
||||||
// : value === "failed"
|
// : value === "failed"
|
||||||
// ? "destructive"
|
// ? "destructive"
|
||||||
// : "secondary"
|
// : "secondary"
|
||||||
// }
|
// }
|
||||||
// >
|
// >
|
||||||
// {value}
|
// {value}
|
||||||
// </Badge>
|
// </Badge>
|
||||||
// </div>
|
// </div>
|
||||||
// );
|
// );
|
||||||
// },
|
// },
|
||||||
// },
|
// },
|
||||||
{
|
{
|
||||||
accessorKey: "Availability",
|
accessorKey: "Availability",
|
||||||
header: ({ column }) => {
|
header: ({ column }) => {
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
>
|
>
|
||||||
Availability
|
Availability
|
||||||
<ArrowUpDown className="ml-2 h-4 w-4" />
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const value = row.getValue("Availability") as string;
|
const value = row.getValue("Availability") as string;
|
||||||
return (
|
return (
|
||||||
<div className="capitalize">
|
<div className="capitalize">
|
||||||
<Badge
|
<Badge
|
||||||
variant={
|
variant={
|
||||||
value === "Active"
|
value === "Active"
|
||||||
? "default"
|
? "default"
|
||||||
: value === "Drain"
|
: value === "Drain"
|
||||||
? "destructive"
|
? "destructive"
|
||||||
: "secondary"
|
: "secondary"
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{value}
|
{value}
|
||||||
</Badge>
|
</Badge>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "ManagerStatus",
|
accessorKey: "ManagerStatus",
|
||||||
header: ({ column }) => {
|
header: ({ column }) => {
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
>
|
>
|
||||||
ManagerStatus
|
ManagerStatus
|
||||||
<ArrowUpDown className="ml-2 h-4 w-4" />
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => (
|
||||||
<div className="lowercase">{row.getValue("ManagerStatus")}</div>
|
<div className="lowercase">{row.getValue("ManagerStatus")}</div>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "actions",
|
id: "actions",
|
||||||
enableHiding: false,
|
enableHiding: false,
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
return (
|
return (
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
<Button variant="ghost" className="h-8 w-8 p-0">
|
<Button variant="ghost" className="h-8 w-8 p-0">
|
||||||
<span className="sr-only">Open menu</span>
|
<span className="sr-only">Open menu</span>
|
||||||
<MoreHorizontal className="h-4 w-4" />
|
<MoreHorizontal className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent align="end">
|
<DropdownMenuContent align="end">
|
||||||
<DropdownMenuLabel>Actions</DropdownMenuLabel>
|
<DropdownMenuLabel>Actions</DropdownMenuLabel>
|
||||||
<ShowNodeConfig nodeId={row.original.ID} />
|
<ShowNodeConfig nodeId={row.original.ID} />
|
||||||
<ShowNodeApplications nodeName={row.original.Hostname} />
|
<ShowNodeApplications nodeName={row.original.Hostname} />
|
||||||
{/* <ShowDockerModalLogs
|
{/* <ShowDockerModalLogs
|
||||||
containerId={container.containerId}
|
containerId={container.containerId}
|
||||||
serverId={container.serverId}
|
serverId={container.serverId}
|
||||||
>
|
>
|
||||||
@@ -193,9 +194,9 @@ export const columns: ColumnDef<SwarmList>[] = [
|
|||||||
>
|
>
|
||||||
Terminal
|
Terminal
|
||||||
</DockerTerminalModal> */}
|
</DockerTerminalModal> */}
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
124
apps/dokploy/components/dashboard/swarm/show/deatils-card.tsx
Normal file
124
apps/dokploy/components/dashboard/swarm/show/deatils-card.tsx
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
import { Badge } from "@/components/ui/badge";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogTrigger,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
|
import {
|
||||||
|
AlertCircle,
|
||||||
|
CheckCircle,
|
||||||
|
HelpCircle,
|
||||||
|
Layers,
|
||||||
|
Settings,
|
||||||
|
} from "lucide-react";
|
||||||
|
import { useState } from "react";
|
||||||
|
import ShowNodeApplications from "../applications/show-applications";
|
||||||
|
import { ShowNodeConfig } from "../details/show-node";
|
||||||
|
|
||||||
|
export interface SwarmList {
|
||||||
|
ID: string;
|
||||||
|
Hostname: string;
|
||||||
|
Availability: string;
|
||||||
|
EngineVersion: string;
|
||||||
|
Status: string;
|
||||||
|
ManagerStatus: string;
|
||||||
|
TLSStatus: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface NodeCardProps {
|
||||||
|
node: SwarmList;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function NodeCard({ node }: NodeCardProps) {
|
||||||
|
const [showConfig, setShowConfig] = useState(false);
|
||||||
|
const [showServices, setShowServices] = useState(false);
|
||||||
|
|
||||||
|
const getStatusIcon = (status: string) => {
|
||||||
|
switch (status) {
|
||||||
|
case "Ready":
|
||||||
|
return <CheckCircle className="h-4 w-4 text-green-500" />;
|
||||||
|
case "Down":
|
||||||
|
return <AlertCircle className="h-4 w-4 text-red-500" />;
|
||||||
|
default:
|
||||||
|
return <HelpCircle className="h-4 w-4 text-yellow-500" />;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card className="w-full">
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className="flex items-center justify-between">
|
||||||
|
<span className="flex items-center gap-2">
|
||||||
|
{getStatusIcon(node.Status)}
|
||||||
|
{node.Hostname}
|
||||||
|
</span>
|
||||||
|
<Badge variant="outline" className="text-xs">
|
||||||
|
{node.ManagerStatus || "Worker"}
|
||||||
|
</Badge>
|
||||||
|
</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<div className="grid gap-2 text-sm">
|
||||||
|
<div className="flex justify-between">
|
||||||
|
<span className="font-medium">Status:</span>
|
||||||
|
<span>{node.Status}</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex justify-between">
|
||||||
|
<span className="font-medium">Availability:</span>
|
||||||
|
<span>{node.Availability}</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex justify-between">
|
||||||
|
<span className="font-medium">Engine Version:</span>
|
||||||
|
<span>{node.EngineVersion}</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex justify-between">
|
||||||
|
<span className="font-medium">TLS Status:</span>
|
||||||
|
<span>{node.TLSStatus}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-2 mt-4">
|
||||||
|
<ShowNodeConfig nodeId={node.ID} />
|
||||||
|
{/* <Dialog open={showConfig} onOpenChange={setShowConfig}>
|
||||||
|
<DialogTrigger asChild>
|
||||||
|
<Button variant="outline" size="sm" className="w-full">
|
||||||
|
<Settings className="h-4 w-4 mr-2" />
|
||||||
|
Config
|
||||||
|
</Button>
|
||||||
|
</DialogTrigger>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Node Configuration</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className="mt-4">
|
||||||
|
<pre className="bg-gray-100 p-4 rounded-md overflow-auto">
|
||||||
|
{JSON.stringify(node, null, 2)}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog> */}
|
||||||
|
<ShowNodeApplications nodeName="node.Hostname" />
|
||||||
|
{/* <Dialog open={showServices} onOpenChange={setShowServices}>
|
||||||
|
<DialogTrigger asChild>
|
||||||
|
<Button variant="outline" size="sm" className="w-full">
|
||||||
|
<Layers className="h-4 w-4 mr-2" />
|
||||||
|
Services
|
||||||
|
</Button>
|
||||||
|
</DialogTrigger>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Node Services</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className="mt-4">
|
||||||
|
<p>Service information would be displayed here.</p>
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog> */}
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -7,176 +7,176 @@ import { useEffect, useMemo, useState } from "react";
|
|||||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "../ui/tabs";
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "../ui/tabs";
|
||||||
|
|
||||||
interface TabInfo {
|
interface TabInfo {
|
||||||
label: string;
|
label: string;
|
||||||
tabLabel?: string;
|
tabLabel?: string;
|
||||||
description: string;
|
description: string;
|
||||||
index: string;
|
index: string;
|
||||||
type: TabState;
|
type: TabState;
|
||||||
isShow?: ({ rol, user }: { rol?: Auth["rol"]; user?: User }) => boolean;
|
isShow?: ({ rol, user }: { rol?: Auth["rol"]; user?: User }) => boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TabState =
|
export type TabState =
|
||||||
| "projects"
|
| "projects"
|
||||||
| "monitoring"
|
| "monitoring"
|
||||||
| "settings"
|
| "settings"
|
||||||
| "traefik"
|
| "traefik"
|
||||||
| "requests"
|
| "requests"
|
||||||
| "docker"
|
| "docker"
|
||||||
| "swarm";
|
| "swarm";
|
||||||
|
|
||||||
const getTabMaps = (isCloud: boolean) => {
|
const getTabMaps = (isCloud: boolean) => {
|
||||||
const elements: TabInfo[] = [
|
const elements: TabInfo[] = [
|
||||||
{
|
{
|
||||||
label: "Projects",
|
label: "Projects",
|
||||||
description: "Manage your projects",
|
description: "Manage your projects",
|
||||||
index: "/dashboard/projects",
|
index: "/dashboard/projects",
|
||||||
type: "projects",
|
type: "projects",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!isCloud) {
|
if (!isCloud) {
|
||||||
elements.push(
|
elements.push(
|
||||||
{
|
{
|
||||||
label: "Monitoring",
|
label: "Monitoring",
|
||||||
description: "Monitor your projects",
|
description: "Monitor your projects",
|
||||||
index: "/dashboard/monitoring",
|
index: "/dashboard/monitoring",
|
||||||
type: "monitoring",
|
type: "monitoring",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Traefik",
|
label: "Traefik",
|
||||||
tabLabel: "Traefik File System",
|
tabLabel: "Traefik File System",
|
||||||
description: "Manage your traefik",
|
description: "Manage your traefik",
|
||||||
index: "/dashboard/traefik",
|
index: "/dashboard/traefik",
|
||||||
isShow: ({ rol, user }) => {
|
isShow: ({ rol, user }) => {
|
||||||
return Boolean(rol === "admin" || user?.canAccessToTraefikFiles);
|
return Boolean(rol === "admin" || user?.canAccessToTraefikFiles);
|
||||||
},
|
},
|
||||||
type: "traefik",
|
type: "traefik",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Docker",
|
label: "Docker",
|
||||||
description: "Manage your docker",
|
description: "Manage your docker",
|
||||||
index: "/dashboard/docker",
|
index: "/dashboard/docker",
|
||||||
isShow: ({ rol, user }) => {
|
isShow: ({ rol, user }) => {
|
||||||
return Boolean(rol === "admin" || user?.canAccessToDocker);
|
return Boolean(rol === "admin" || user?.canAccessToDocker);
|
||||||
},
|
},
|
||||||
type: "docker",
|
type: "docker",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Swarm",
|
label: "Swarm & Server",
|
||||||
description: "Manage your docker swarm",
|
description: "Manage your docker swarm and Servers",
|
||||||
index: "/dashboard/swarm",
|
index: "/dashboard/swarm",
|
||||||
isShow: ({ rol, user }) => {
|
isShow: ({ rol, user }) => {
|
||||||
return Boolean(rol === "admin" || user?.canAccessToDocker);
|
return Boolean(rol === "admin" || user?.canAccessToDocker);
|
||||||
},
|
},
|
||||||
type: "swarm",
|
type: "swarm",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Requests",
|
label: "Requests",
|
||||||
description: "Manage your requests",
|
description: "Manage your requests",
|
||||||
index: "/dashboard/requests",
|
index: "/dashboard/requests",
|
||||||
isShow: ({ rol, user }) => {
|
isShow: ({ rol, user }) => {
|
||||||
return Boolean(rol === "admin" || user?.canAccessToDocker);
|
return Boolean(rol === "admin" || user?.canAccessToDocker);
|
||||||
},
|
},
|
||||||
type: "requests",
|
type: "requests",
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
elements.push({
|
elements.push({
|
||||||
label: "Settings",
|
label: "Settings",
|
||||||
description: "Manage your settings",
|
description: "Manage your settings",
|
||||||
type: "settings",
|
type: "settings",
|
||||||
index: isCloud
|
index: isCloud
|
||||||
? "/dashboard/settings/profile"
|
? "/dashboard/settings/profile"
|
||||||
: "/dashboard/settings/server",
|
: "/dashboard/settings/server",
|
||||||
});
|
});
|
||||||
|
|
||||||
return elements;
|
return elements;
|
||||||
};
|
};
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
tab: TabState;
|
tab: TabState;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const NavigationTabs = ({ tab, children }: Props) => {
|
export const NavigationTabs = ({ tab, children }: Props) => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { data } = api.auth.get.useQuery();
|
const { data } = api.auth.get.useQuery();
|
||||||
const [activeTab, setActiveTab] = useState<TabState>(tab);
|
const [activeTab, setActiveTab] = useState<TabState>(tab);
|
||||||
const { data: isCloud } = api.settings.isCloud.useQuery();
|
const { data: isCloud } = api.settings.isCloud.useQuery();
|
||||||
const tabMap = useMemo(() => getTabMaps(isCloud ?? false), [isCloud]);
|
const tabMap = useMemo(() => getTabMaps(isCloud ?? false), [isCloud]);
|
||||||
const { data: user } = api.user.byAuthId.useQuery(
|
const { data: user } = api.user.byAuthId.useQuery(
|
||||||
{
|
{
|
||||||
authId: data?.id || "",
|
authId: data?.id || "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
enabled: !!data?.id && data?.rol === "user",
|
enabled: !!data?.id && data?.rol === "user",
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setActiveTab(tab);
|
setActiveTab(tab);
|
||||||
}, [tab]);
|
}, [tab]);
|
||||||
|
|
||||||
const activeTabInfo = useMemo(() => {
|
const activeTabInfo = useMemo(() => {
|
||||||
return tabMap.find((tab) => tab.type === activeTab);
|
return tabMap.find((tab) => tab.type === activeTab);
|
||||||
}, [activeTab]);
|
}, [activeTab]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="gap-12">
|
<div className="gap-12">
|
||||||
<header className="mb-6 flex w-full items-center gap-2 justify-between flex-wrap">
|
<header className="mb-6 flex w-full items-center gap-2 justify-between flex-wrap">
|
||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
<h1 className="text-xl font-bold lg:text-3xl">
|
<h1 className="text-xl font-bold lg:text-3xl">
|
||||||
{activeTabInfo?.label}
|
{activeTabInfo?.label}
|
||||||
</h1>
|
</h1>
|
||||||
<p className="lg:text-medium text-muted-foreground">
|
<p className="lg:text-medium text-muted-foreground">
|
||||||
{activeTabInfo?.description}
|
{activeTabInfo?.description}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{tab === "projects" &&
|
{tab === "projects" &&
|
||||||
(data?.rol === "admin" || user?.canCreateProjects) && <AddProject />}
|
(data?.rol === "admin" || user?.canCreateProjects) && <AddProject />}
|
||||||
</header>
|
</header>
|
||||||
<div className="flex w-full justify-between gap-8 ">
|
<div className="flex w-full justify-between gap-8 ">
|
||||||
<Tabs
|
<Tabs
|
||||||
value={activeTab}
|
value={activeTab}
|
||||||
className="w-full"
|
className="w-full"
|
||||||
onValueChange={async (e) => {
|
onValueChange={async (e) => {
|
||||||
setActiveTab(e as TabState);
|
setActiveTab(e as TabState);
|
||||||
const tab = tabMap.find((tab) => tab.type === e);
|
const tab = tabMap.find((tab) => tab.type === e);
|
||||||
router.push(tab?.index || "");
|
router.push(tab?.index || "");
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className="flex flex-row items-center justify-between w-full gap-4 max-sm:overflow-x-auto overflow-y-hidden border-b border-b-divider pb-1">
|
<div className="flex flex-row items-center justify-between w-full gap-4 max-sm:overflow-x-auto overflow-y-hidden border-b border-b-divider pb-1">
|
||||||
<TabsList className="bg-transparent relative px-0">
|
<TabsList className="bg-transparent relative px-0">
|
||||||
{tabMap.map((tab, index) => {
|
{tabMap.map((tab, index) => {
|
||||||
if (tab?.isShow && !tab?.isShow?.({ rol: data?.rol, user })) {
|
if (tab?.isShow && !tab?.isShow?.({ rol: data?.rol, user })) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<TabsTrigger
|
<TabsTrigger
|
||||||
key={tab.type}
|
key={tab.type}
|
||||||
value={tab.type}
|
value={tab.type}
|
||||||
className="relative py-2.5 md:px-5 data-[state=active]:shadow-none data-[state=active]:bg-transparent rounded-md hover:bg-zinc-100 hover:dark:bg-zinc-800 data-[state=active]:hover:bg-zinc-100 data-[state=active]:hover:dark:bg-zinc-800"
|
className="relative py-2.5 md:px-5 data-[state=active]:shadow-none data-[state=active]:bg-transparent rounded-md hover:bg-zinc-100 hover:dark:bg-zinc-800 data-[state=active]:hover:bg-zinc-100 data-[state=active]:hover:dark:bg-zinc-800"
|
||||||
>
|
>
|
||||||
<span className="relative z-[1] w-full">
|
<span className="relative z-[1] w-full">
|
||||||
{tab?.tabLabel || tab?.label}
|
{tab?.tabLabel || tab?.label}
|
||||||
</span>
|
</span>
|
||||||
{tab.type === activeTab && (
|
{tab.type === activeTab && (
|
||||||
<div className="absolute -bottom-[5.5px] w-full">
|
<div className="absolute -bottom-[5.5px] w-full">
|
||||||
<div className="h-0.5 bg-foreground rounded-t-md" />
|
<div className="h-0.5 bg-foreground rounded-t-md" />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</TabsTrigger>
|
</TabsTrigger>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</TabsList>
|
</TabsList>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<TabsContent value={activeTab} className="w-full">
|
<TabsContent value={activeTab} className="w-full">
|
||||||
{children}
|
{children}
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
|
import { ShowServers } from "@/components/dashboard/settings/servers/show-servers";
|
||||||
|
import SwarmMonitorCard from "@/components/dashboard/swarm/monitoring-card";
|
||||||
|
import ShowApplicationServers from "@/components/dashboard/swarm/servers/show-server";
|
||||||
import ShowSwarmNodes from "@/components/dashboard/swarm/show/show-nodes";
|
import ShowSwarmNodes from "@/components/dashboard/swarm/show/show-nodes";
|
||||||
import { DashboardLayout } from "@/components/layouts/dashboard-layout";
|
import { DashboardLayout } from "@/components/layouts/dashboard-layout";
|
||||||
|
import { Separator } from "@/components/ui/separator";
|
||||||
import { appRouter } from "@/server/api/root";
|
import { appRouter } from "@/server/api/root";
|
||||||
|
import { api } from "@/utils/api";
|
||||||
import { IS_CLOUD, validateRequest } from "@dokploy/server";
|
import { IS_CLOUD, validateRequest } from "@dokploy/server";
|
||||||
import { createServerSideHelpers } from "@trpc/react-query/server";
|
import { createServerSideHelpers } from "@trpc/react-query/server";
|
||||||
import type { GetServerSidePropsContext } from "next";
|
import type { GetServerSidePropsContext } from "next";
|
||||||
@@ -8,7 +13,19 @@ import React, { type ReactElement } from "react";
|
|||||||
import superjson from "superjson";
|
import superjson from "superjson";
|
||||||
|
|
||||||
const Dashboard = () => {
|
const Dashboard = () => {
|
||||||
return <ShowSwarmNodes />;
|
return (
|
||||||
|
<>
|
||||||
|
<div className="flex flex-wrap gap-4 py-4">
|
||||||
|
<SwarmMonitorCard />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* <h1>Swarm Nodes</h1>
|
||||||
|
<ShowSwarmNodes />
|
||||||
|
<Separator />
|
||||||
|
<h1 className="mt-24">Server Nodes</h1>
|
||||||
|
<ShowApplicationServers /> */}
|
||||||
|
</>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Dashboard;
|
export default Dashboard;
|
||||||
|
|||||||
Reference in New Issue
Block a user